import axios from "axios";
import { loadStorage } from "@/utils/cache"

let instance = axios.create({
  timeout: 30000,
  baseURL: import.meta.env.VITE_APP_API
});


instance.interceptors.request.use(
  (config: any) => {
    var token:string = '' 
    if (token) {
      config.headers["token"] = token;
    }

    return config;
  },
  error => {
    console.log(error, "请求拦截error")
    return Promise.reject(error);
  }
);

instance.interceptors.response.use(
  response => {
    const res = response.data;
    if (res.code !== 1000) {
      
    }
    return res;
  },
  error => {
    console.log(error, "响应拦截   error")

    if (error && error.response) {
      switch (error.response.status) {
        case 500:
          
          break;
      }
    }
    return Promise.reject(error);
  }
);
class Http {
  static async get(url: string, params: any) {
    return await instance.get(url, { params });
  }
  static async post(url: string, params: any) {
    return await instance.post(url, params);
  }
}

export default Http;
